<template>
  <div class="loginBox">
    <div class="login">
      <h1>用户登录</h1>
      <el-form :model="formData">
        <el-form-item style="margin-bottom: 10px;">
          <el-input placeholder="账号" v-model="formData.username" clearable></el-input>
        </el-form-item>
        <el-form-item style="margin-bottom: 10px;">
          <el-input @keyup.enter.native="doSubmit" placeholder="密码" v-model="formData.password" show-password></el-input>
        </el-form-item>
        <div>
          <el-button type="primary" @click="doSubmit()">登录</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import store from '@/vuex/store'
export default {
  name: "login",
  data() {
    return {
      formData: {
        username: '',
        password: ''
      },
      menuList: []
    };
  },
  methods:{
    doSubmit() {
      let _this = this;
      this.$http.post('/user/login',this.formData).then(res => {
        if (res.status === 200) {          
          this.$message({
            message: '登录成功！',
            type: 'success',
            center: true
          });
          this.menuList = res.data.result.menu;
          this.$store.dispatch('setUserInfo', res.data.result.user_info);       
          this.$store.commit('TOKEN', res.data.result.token);
          this.$store.commit('AUTH_LIST', res.data.result.auth);
          this.$store.dispatch('setMenuList', res.data.result.menu);
          _this.$router.push('/');
        }else{
          console.log(aaa);
        }
      })
    }
  },
  mounted(){
    console.log(this.$store)
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.loginBox {
  overflow: hidden;
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #ccc; 
  
}
.login {
  position: absolute;
  top: 50%;
  left: 50%;
  box-sizing: border-box;
  max-width: 400px;
  height: auto;
  transform: translate(-50%, -50%);
  background-color: aquamarine;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  -moz-box-shadow: 0 3px 0 rgba(12, 12, 12, 0.03);
  -webkit-box-shadow: 0 3px 0 rgba(12, 12, 12, 0.03);
  box-shadow: 0 3px 0 rgba(12, 12, 12, 0.03);
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  border-radius: 3px;
  padding: 30px 30px 50px 30px;
  text-align: center;
}
.login h1 {
  font-size: 24px;
  line-height: 24px;
  margin-bottom: 24px;
  letter-spacing: 0.2em;
}
.login .elRadioBox {
  width: 100%;
  height: 40px;
  margin-top: 14px;
}
.el-radio {
  color: #fff;
}
.login .el-input {
  width: 260px;
  height: 40px;
  margin-bottom: 14px;
}
.login .el-button {
  width: 260px;
  height: 40px;
}
</style>
